<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	String path = request.getContextPath();
%>
<html>
<head>
		<title>订单表单页面</title>
		<meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
       <%--  <link rel="stylesheet" href="<%=path%>/css/lightbox.css" /> --%>
		<link rel="stylesheet" href="<%=path%>/css/bootstrap.min.css" />
		<link rel="stylesheet" href="<%=path%>/css/font-awesome.css" />
        <link rel="stylesheet" href="<%=path%>/css/jquery-ui.css" />
		<link rel="stylesheet" href="<%=path%>/css/icheck/flat/blue.css" />
		<link rel="stylesheet" href="<%=path%>/css/select2.css" />		
		<link rel="stylesheet" href="<%=path%>/css/unicorn.css" />
		<link rel="stylesheet" href="<%=path%>/css/mx.css" />
		<script type="text/javascript" src="<%=path%>/js/jquery-1.8.2.min.js"></script>
		<script type="text/javascript" src="<%=path%>/js/source/jquery.fancybox.js?v=2.1.3"></script>
	<link rel="stylesheet" type="text/css" href="<%=path%>/js/source/jquery.fancybox.css?v=2.1.2" media="screen" />
		<!--[if lt IE 9]>
		<script type="text/javascript" src="js/respond.min.js"></script>
		<![endif]-->
		<%-- <script src="<%=path%>/js/jquery.min.js"></script> --%>
	<script>
		  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
		  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
		  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
		  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

		  ga('create', 'UA-44987299-1', 'bootstrap-hunter.com');
		  ga('send', 'pageview');
		 
		</script>
		<style type="text/css">
		.fancybox-custom .fancybox-skin {
			box-shadow: 0 0 50px #222;
		}
	</style>
</head>	
<body data-color="grey" class="flat">
		<div id="wrapper">
			<div id="header">
				<h1><a href="<%=path %>/admins/index">宣 臻  管 理</a></h1>	
				<a id="menu-trigger" href="#"><i class="fa fa-bars"></i></a>	
			</div>
		
			<div id="user-nav">
	            <ul class="btn-group">
	            	<li class="btn" ><a title="" href="#"><i class="fa fa-user"></i> <span class="text">${admins.userName}</span></a></li>
	          		<li class="btn dropdown open" id="menu-messages"><a href="#" data-toggle="dropdown" data-target="#menu-messages" class="dropdown-toggle unreaddeal"><i class="fa fa-envelope"></i> <span class="text">Messages</span> <span id="unread" class="label label-danger">${unReadCount }</span> <b class="caret"></b></a>
	                    <audio id="music1"  preload="preload">
	                    	<source src="<%=path%>/img/reservation/msg.wav" type="audio/mpeg">
						</audio>
	                    <!-- <ul class="dropdown-menu messages-menu">
	                        <li class="title"><i class="fa fa-envelope-alt"></i>Messages<a class="title-btn" href="#" title="Write new message"><i class="fa fa-share"></i></a></li>
	                        <li class="message-item">
	                        	<a href="#">
		                            <img alt="User Icon" src="img/demo/av1.jpg">
		                            <div class="message-content">
		                            	<span class="message-time">
			                                3 mins ago
			                            </span>
		                                <span class="message-sender">
		                                    Nunc Cenenatis
		                                </span>
		                                <span class="message">
		                                    Hi, can you meet me at the office tomorrow morning?
		                                </span>
		                            </div>
	                        	</a>
	                        </li>
	                    </ul> -->
	                </li>
	                <li class="btn"><a title="" href="<%=path%>/admins/out"><i class="fa fa-share"></i> <span class="text">登出</span></a></li>
	            </ul>
	        </div>
	       
	       

			<div id="sidebar">
				<div id="search">
					<!-- <input type="text" placeholder="Search here..."/><button type="submit" class="tip-right" title="Search"><i class="fa fa-search"></i></button> -->
				</div>	
				<ul>
					<%--  <li ><a href="<%=path %>/admins/index"><i class="fa fa-home"></i> <span>指示板</span></a></li>  --%>
					<%-- <li ><a href="<%=path%>/user/selectUser"><i class="fa fa-th"></i> <span>接龙用户表单</span></a></li> --%>
					<li ><a href="<%=path%>/admins/jielong"><i class="fa fa-th"></i> <span>接龙用户表单</span></a></li>
					<li ><a href="<%=path%>/admins/dating"><i class="fa fa-th"></i> <span>快闪交友用户表单</span></a></li>
					<li ><a href="<%=path%>/admins/datingcount"><i class="fa fa-th"></i> <span>快闪交友数据统计</span></a></li>
					<li class="active"><a href="javascript:void(0);"><i class="fa fa-th"></i> <span>car2go 约车调度</span></a></li>
					
				</ul>
			
			</div>
		
		
		
		<div id="content">
			<div id="breadcrumb">
				<a href="#" title="Go to Home" class="tip-bottom"><i class="fa fa-home"></i>管理</a>
				<a href="#" class="current">Car2go 约车调度</a>
			</div>
				<div class="row">
					<div class="col-xs-12">
						
						<div class="widget-box">
							<div class="widget-title">
								<span class="icon">
									<i class="fa fa-th"></i>
								</span>
								<h5>预约表单</h5>
							</div>
							<div class="widget-content  nopadding">
								<table class="table table-bordered table-striped table-hover" style="text-align: center;">
									<thead>
									<tr>
								<!-- 	<th><input type="checkbox" id="title-table-checkbox" name="title-table-checkbox" /></th> -->
									<th>序号</th>
									<th>单号</th>
									<th>预约用户</th>
									<th>约车手机</th>
									<th>交车地址</th>
									<th>订单时间</th>
									<th>送车时间</th>
									<th>订单状态</th>
									<th>操作</th>
									</tr>
									</thead>
									<tbody>
										<c:forEach items="${resList}" var="list" varStatus="s">
											<tr class="rlist">
												<%-- <td>${s.index+1}</td> --%>
												<td class="rid" >${list.id}</td>
												<td>${list.orderNo}</td>
												<td>${list.name}</td>
												<td>${list.phone}</td>
												<td>${list.address}</td>
												<td class="times">${list.createTime.toLocaleString()}</td>
												<td class="times">${list.time.toLocaleString()}</td>
												<td class="state">
													<c:if test="${list.state eq 'UNREAD'}">未读</c:if>
													<c:if test="${list.state eq 'RECEIVE'}">未处理</c:if>
													<c:if test="${list.state eq 'UNFINISH'}">派送中</c:if>
													<c:if test="${list.state eq 'FINISH'}">已完成</c:if>
													<c:if test="${list.state eq 'REFUSE'}">被拒绝</c:if>
													<c:if test="${list.state eq 'CANCEL'}">客户取消</c:if>
													<c:if test="${list.state eq 'BEICANCEL'}">爽约取消</c:if>
												</td>
												<td class="cho">
													<c:if test="${list.state eq 'UNREAD'}"><a href="javascript:;" class="layui-btn layui-btn-primary layer-demolist" ><button name="formUp" class="btn btn-dark-blue btn-sm">派单</button></a></c:if>
													<c:if test="${list.state eq 'RECEIVE'}"><a href="javascript:;" class="layui-btn layui-btn-primary layer-demolist" ><button name="formUp" class="btn btn-dark-blue btn-sm">派单</button></a></c:if>
													<c:if test="${list.state eq 'RECEIVE' ||list.state eq 'UNREAD'}"><a href="javascript:;" ><button name="" class="btn btn-dark-red btn-sm dis">拒绝</button></a></c:if>
												</td>
												
											</tr>
										</c:forEach>
									</tbody>
									</table>
									<div class="ym" id="ymm">
									<div class="fy" id="yeshu">共${pageCount }页</div>
									<div class="fy" id="pageDown">→     下一页</div>
										<ul>
										
											<c:forEach var="i" begin="1" end="${pageCount}" step="1">
												<li>${i}</li>
											</c:forEach>
									
										</ul>
										<div class="fy" id="pageUp">上一页        ←</div>
									</div>  
							</div>
						</div>
					</div>
				</div>
		</div>
		<div class="row">
			<div id="footer" class="col-xs-12">
				XUANZHEN&nbsp; 2012 - 2013 &copy; Unicorn Admin. Brought to you 
			</div>
		</div>
		
            
            <script src="<%=path%>/js/jquery-ui.custom.js"></script>
            <script src="<%=path%>/js/bootstrap.min.js"></script>
            <script src="<%=path%>/js/jquery.icheck.min.js"></script>
            <script src="<%=path%>/js/select2.min.js"></script>
            <script src="<%=path%>/js/jquery.dataTables.min.js"></script>      
            <script src="<%=path%>/js/jquery.nicescroll.min.js"></script>
            <script src="<%=path%>/js/unicorn.js"></script>
            <script src="<%=path%>/js/unicorn.tables.js"></script>
            <script src="<%=path%>/js/layer/layer.js"></script>
               <script type="text/javascript">
               (function(global,$){ 
            	   $(".times").each(
	            	        function(){
	            	        	var ss = $(this).text().toLocaleString();
	            	        	$(this).text(ss);
	            	        });
            	  
            	   //播放
               
            	   function bf(){
            		   var audio = document.getElementById('music1'); 
            		   if(audio!==null){             
            		      //检测播放是否已暂停.audio.paused 在播放器播放时返回false.
            		    var index = 0;
            		    audio.addEventListener('ended', function () {
            		        setTimeout(
            		        	function(){
            		        		if(index<5){
            		        			index++;
            		        			audio.play();
            		        		}else{
            		        			index=0;
            		        		}
            		        	}, 50);
            		    }, false);
            		    audio.play();
            		   } 
            	   }
            	  //检查状态
            	  function checkstate(rid){
            		  
            	  }
            	 //选择派发
               $(document).on("click",".paifa",function(){
              		 var rid = $(this).closest('.plist').find(".prid").text();
              		 var pid = $(this).closest('.plist').find(".pid").text();
              		 var pname = $(this).closest('.plist').find(".pname").text();
              		var remark = $(".remark").val().trim();
              		$(".remark").val("");
              		  layer.confirm('确认派发？', {
              			  btn: ['确认','取消'] //按钮
              			  ,zIndex: layer.zIndex //重点1
              			  ,success: function(layero){
              				    layer.setTop(layero); //重点2
              				  }
              			}, function(){
           				 $.ajax({  
       				    	 type: "post",
       			             url:"<%=path%>/reserManage/post", 
       			           	 data: {rid:rid,pid:pid,pname:pname,remark:remark},
       			             dataType: "text",
       			   			async:false,
       			             timeout: 1000,  
       			             cache: false,  
       			             error: posterrorFunction,  //错误执行方法    
       			             success: postsuccessFunction //成功执行方法    
       			         });
                  		 function posterrorFunction() {  
      			              alert("未能显示信息");
      			         } 
                  		 function postsuccessFunction() {
	                  			 $('.rid').each(function(){
	                   				 if($(this).text() == rid){
	                   					$(this).closest('.rlist').find(".state").text("派送中");
	                   					$(this).closest('.rlist').find(".cho").html('');
	                   				 }
	                  			 });
	                  			layer.closeAll();
                  			}
              			 }, function(){
              				layer.closeAll();
              			}); 
              	 });
            	 //页面层-自定义
            	  $(document).on("click",".layui-btn",function(){  
            		 var rid = $(this).closest('.rlist').find(".rid").text();
            		 $.ajax({  
   				    	 type: "post",
   			             url:"<%=path%>/reserManage/checkstate", 
   			           	 data: {rid:rid},
   			             dataType: "text",
   			   			async:false,
   			             timeout: 10000,  
   			             cache: false,  
   			             error: stateerrorFunction,  //错误执行方法    
   			             success: statesuccessFunction //成功执行方法    
   			         });
           		  function stateerrorFunction() {  
 			              alert("订单状态未检测通过");
 			              return false;
 			         }
           		 function statesuccessFunction(data) {  
		              var state = data
		              if(state =='RECEIVE' || state =='UNREAD'){
		            		 //获取送车员悬浮层
		            		 var result = '';
		            		 $.ajax({  
		 				    	 type: "get",
		 			             url:"<%=path%>/reserManage/chick", 
		 			           	 data: {},
		 			             dataType: "json",  
		 			             timeout: 1000,  
		 			             cache: false,  
		 			             error: perrorFunction,  //错误执行方法    
		 			             success: psuccessFunction //成功执行方法    
		 			         });
		              }else{
		            	//询问框
		            	 layer.confirm('订单状态已变更，点击确认刷新页面', {
		            	   btn: ['确认','取消'] //按钮
		            	 }, function(){
		            		 location.reload();
		            	 }, function(){
		            	  layer.closeAll();
		            	 });
		            	return false;
		              } 
		         }
            		 function perrorFunction() {  
			              alert("未能显示信息");
			         }  
           			function psuccessFunction(data) {  
						var json = eval(data);
						 result = '<div class="widget-box">'
							+'<div class="widget-title">'
						+'<span class="icon">'
							+'<i class="fa fa-th"></i>'
						+'</span>'
						+'<h5>配&nbsp;&nbsp;送&nbsp;&nbsp;员&nbsp;&nbsp;选&nbsp;&nbsp;单：</h5>'
					+'</div>'
					+'<div class="widget-content">'
						+'<table class="table table-bordered table-striped table-hover ">'
							+'<thead>'
								+'<tr>'
								+'<th style="display:none;">rid</th>'
								+'<th>配送员编号</th>'
								+'<th>配送员姓名</th>'
								/* +'<th>配送员状态</th>'	 */
									+'<th>操作</th>'
								+'</tr>'
							+'</thead>'
							+'<tbody>';
							/* result = '<div class="sho"><select name="" id=""><option value=""></option></select></div>'; */
                    	$.each(json, function (index, item) {
                    		var record =new Object(); 
                    		record.id=json[index].id;
                          	record.name= json[index].name;
    	                   	record.state=json[index].state;
    	                   	result+='<tr class="plist" style="text-align:center;vertical-align:middle;">'
    	                   		+'<td class="prid" style="display:none;">'+rid+'</td>'
    	                   	+'<td class="pid">'+record.id+'</td>'
    	                   	+'<td class="pname">'+record.name+'</td>'
    	                   	/* +'<td>'+record.state+'</td>' */
    	                   	+'<td><button name="" class="btn btn-dark-green btn-sm paifa">派发</button></td>';
    	                   	
                    	})
                    	result+='</tbody></table></div></div>'
                    		layer.open({
                       	     type: 1,
                       	     title: "选择配送员",
                       	     closeBtn: 0,
                       	     shadeClose: true,
                       	     skin: 'youClass',
                       	     content: '<div >'
                       	     +result
                       	     +'</div><div style="padding:15px 5px;"><input style="width:330px;" class="remark layui-input" type="text" placeholder="备注信息" ></div>'
                       	   });
			         }
            		 
            	 });
            	  $(document).on("click",".dis",function(){
            		 var rid = $(this).closest('.rlist').find(".rid").text();
            		 var sss = $(this);
            		 //检查状态
            		  $.ajax({  
   				    	 type: "post",
   			             url:"<%=path%>/reserManage/checkstate", 
   			           	 data: {rid:rid},
   			             dataType: "text",
   			   			async:false,
   			             timeout: 10000,  
   			             cache: false,  
   			             error: stateerrorFunction,  //错误执行方法    
   			             success: statesuccessFunction //成功执行方法    
   			         });
           		  function stateerrorFunction() {  
 			              alert("订单状态未检测通过");
 			              return false;
 			         }
           		 function statesuccessFunction(data) {  
		              var state = data
		              if(state =='RECEIVE' || state =='UNREAD'){
		            	  $.ajax({  
		 				    	 type: "post",
		 			             url:"<%=path%>/reserManage/dis", 
		 			           	 data: {rid:rid},
		 			             dataType: "json",  
		 			             timeout: 1000,  
		 			             cache: false,  
		 			             error: dserrorFunction,  //错误执行方法    
		 			             success: dssuccessFunction //成功执行方法    
		 			         });
		              }else{
		            	//询问框
		            	 layer.confirm('订单状态已变更，点击确认刷新页面', {
		            	   btn: ['确认','取消'] //按钮
		            	 }, function(){
		            		 location.reload();
		            	 }, function(){
		            	  layer.closeAll();
		            	 });
		            	return false;
		              } 
		         }
            		 function dserrorFunction() {  
			              alert("未能拒绝");
			         }
            		 function dssuccessFunction() {  
            			 sss.closest('.rlist').find(".state").text("被拒绝");
            			 sss.closest('.rlist').find(".cho").html("");
			         }
            	 });
            	  $(document).on("click",".unreaddeal",function(){
            		 var pageNo = 0;
            		 $.ajax({  
 				    	 type: "post",
 			             url:"<%=path%>/reserManage/unreaddeal", 
 			           	 data: {pagebegin:pageNo},
 			             dataType: "json",  
 			             timeout: 1000,  
 			             cache: false,  
 			             error: errorFunction,  //错误执行方法    
 			             success: successFunction //成功执行方法    
 			         });
        		});
        		
            	   
	            	//显示未读数
	            	 showUnReadCount(); 
	            	function showUnReadCount(){
	            		setInterval(function(){
	            			$.ajax({  
		 				    	 type: "post",
		 			             url:"<%=path%>/reserManage/unread", 
		 			           	 data: {},
		 			             dataType: "json",  
		 			             timeout: 1000,  
		 			             cache: false,  
		 			             error: unreaderrorFunction,  //错误执行方法    
		 			             success: unreadsuccessFunction //成功执行方法    
		 			         });
	            		},12000);
	            		
	            		function unreaderrorFunction() {  
				              alert("未能显示未读信息");
				         }  
	            		function unreadsuccessFunction(data) {
	            			var now =  $("#unread").text();
	            			if(now<data){
	            				bf();
	            			}
				              $("#unread").text(data);
				         }
	 			    }
	            	//分页控件
	            	var pageNo = 0;
			    	var pageCount=${pageCount};
			    	function showComment(){
	 			    	$.ajax({  
	 				    	 type: "post",
	 			             url:"<%=path%>/reserManage/newPage", 
	 			           	 data: {pagebegin:pageNo},
	 			             dataType: "json",  
	 			             timeout: 1000,  
	 			             cache: false,  
	 			             error: errorFunction,  //错误执行方法    
	 			             success: successFunction //成功执行方法    
	 			         });
	 			    }
			    	 function errorFunction() {  
			              alert("未能成功查询");
			         }  
			         function successFunction(data) {
			        	 var json=eval(data);
			        	 var html="";
			        	 var htmls='';
			        	 $.each(json, function (index, item) {  
			                 //循环获取数据   
			                 var s= "<%=path%>";
			                 var record =new Object(); 
			                	 record.id=json[index].id;
			                	 record.orderNo=json[index].orderNo;
			                	 record.name=json[index].name;
			                	 record.phone=json[index].phone;
			                	 record.address=json[index].address;
			                	 record.createTime=getNowFormatDate(json[index].createTime);
			                	 record.time=getNowFormatDate(json[index].time);
			                	 record.state=json[index].state;
			                 	if(record.state == 'UNREAD'){
			                 		record.state="未读";
			                 	}
			                 	if(record.state == 'RECEIVE'){
			                 		record.state="未处理";
			                 	}
			                 	if(record.state == 'UNFINISH'){
			                 		record.state="派送中";
			                 	}
			                 	if(record.state == 'FINISH'){
			                 		record.state="已完成";
			                 	}
			                 	if(record.state == 'BEICANCEL'){
			                 		record.state="爽约取消";
			                 	}
			                 	if(record.state == 'REFUSE'){
			                 		record.state="被拒绝";
			                 	}
			                 	if(record.state == 'CANCEL'){
			                 		record.state="客户取消";
			                 	}
			                   htmls += '<tr class="rlist">'
									+'<td class="rid" >'+record.id+'</td>'
									+'<td>'+record.orderNo+'</td>'
									+'<td>'+record.name+'</td>'
									+'<td>'+record.phone+'</td>'
									+'<td>'+record.address+'</td>'
									+'<td class="times">'+record.createTime+'</td>'
									+'<td class="times">'+record.time+'</td>'
									+'<td class="state">'+record.state+'</td>'
									+'<td class="cho">';
								if(record.state == '未读'){
									htmls+='<a href="javascript:;" class="layui-btn layui-btn-primary layer-demolist" ><button name="formUp" class="btn btn-dark-blue btn-sm">派单</button></a>';
									htmls+='<a style="margin-left:3px;" href="javascript:;" class="dis"><button name="" class="btn btn-dark-red btn-sm dis">拒绝</button></a>';
								}else if(record.state == '未处理' ){
									htmls+='<a href="javascript:;" class="layui-btn layui-btn-primary layer-demolist" ><button name="formUp" class="btn btn-dark-blue btn-sm">派单</button></a>';
									htmls+='<a style="margin-left:3px;" href="javascript:;" class="dis"><button name="" class="btn btn-dark-red btn-sm dis">拒绝</button></a>';
								}
								
								htmls+='</td></tr>'
			             });
			        	 $("tbody").html(html+htmls);
			            	
			         }
			        
					//上一页
					$("#pageUp").click(function(){
						if(pageNo>0){
							pageNo-=1;
							showPageColor();
							hidePageNo();
						}
						showComment();
					});
				    //下一页
					$("#pageDown").click(function(){
						if(pageNo<pageCount){
							pageNo+=1;
							showPageColor();
							hidePageNo();
						}
						showComment();
					});
					showPageColor();
					hidePageNo();
					function showPageColor(){
				    	$("#ymm ul li:eq("+pageNo+")").css('color','#e74c3c');
				    	for(var i=0;i<pageCount+1;i++){
				 			if(i!=pageNo){
				 				$("#ymm ul li:eq("+i+")").css('color','#333');
				 			}
				 		}
				    }
					function hidePageNo(){
						
						for(var i=0;i<pageCount+1;i++){
				 			if(i<pageNo-4 | i>pageNo+4){
				 				$("#ymm ul li:eq("+i+")").css('display','none');
				 			}else{
				 				$("#ymm ul li:eq("+i+")").css('display','');
				 			}
				 			
				 		}
					}
				    //点击到页数
				 	$(".ym ul li").click(function(){
				 		pageNo=this.innerText-1;
				 		showPageColor();
				 		 showComment();
				 		hidePageNo();
				 	});
				 	 function getNowFormatDate(time) {
						    var date = new Date(time);
						    var seperator1 = "-";
						    var seperator2 = ":";
						    var year = date.getFullYear();
						    var month = date.getMonth() + 1;
						    var strDate = date.getDate();
						    if (month >= 1 && month <= 9) {
						        month = "0" + month;
						    }
						    if (strDate >= 0 && strDate <= 9) {
						        strDate = "0" + strDate;
						    }
						    var currentdate = year + seperator1 + month + seperator1 + strDate
						            + " " + date.getHours() + seperator2 + date.getMinutes()
						            + seperator2 + date.getSeconds();
						    return currentdate;
						}
	            	
	   		 })(window,jQuery);
			</script>
            
	</body>
</html>